package com.itheima.tlias84.service.impl;

import com.itheima.tlias84.dao.mapper.ReportMapper;
import com.itheima.tlias84.service.ReportService;
import com.itheima.tlias84.service.vo.JobDataVO;
import com.itheima.tlias84.service.vo.ReportVO;
import com.itheima.tlias84.service.vo.StuCountVO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ReportServiceImpl implements ReportService {

    @Resource
    ReportMapper reportMapper;

    @Override
    public List<ReportVO> getEmpGenderData() {
        List<ReportVO> data = reportMapper.getGenderData();
        data.forEach(vo -> {
            //将数字转换为中文
            vo.setName(vo.getName().equals("1") ? "男性员工" : "女性员工");
        });
        return data;
    }

    @Override
    public JobDataVO getEmpJobData() {
        List<ReportVO> jobData = reportMapper.getJobData();
        ArrayList<String> nameList = new ArrayList<>();
        ArrayList<Integer> valueList = new ArrayList<>();
        jobData.forEach(e -> {
            switch (e.getName()) {
                case "1":
                    e.setName("班主任");
                    break;
                case "2":
                    e.setName("讲师");
                    break;
                case "3":
                    e.setName("学工主管");
                    break;
                case "4":
                    e.setName("教研主管");
                    break;
                case "5":
                    e.setName("咨询师");
                    break;
                default:
                    e.setName("其他");
            }
            nameList.add(e.getName());
            valueList.add(e.getValue());
        });
        return new JobDataVO(nameList, valueList);
    }

    @Override
    public List<ReportVO> getStuDegreeData() {
        List<ReportVO> data = reportMapper.getStuDegreeData();
        data.forEach(vo -> {
            switch (vo.getName()) {
                case "1":
                    vo.setName("初中");
                    break;
                case "2":
                    vo.setName("高中");
                    break;
                case "3":
                    vo.setName("大专");
                    break;
                case "4":
                    vo.setName("本科");
                    break;
                case "5":
                    vo.setName("硕士");
                    break;
                case "6":
                    vo.setName("博士");
                    break;
                default:
                    vo.setName("其他");
            }
        });
        return data;
    }

    @Override
    public StuCountVO getStuCountData() {
        List<ReportVO> data = reportMapper.getStuCountData();
        List<String> clazzList = new ArrayList<>();
        List<Integer> dataList = new ArrayList<>();
        data.forEach(vo -> {
            clazzList.add(vo.getName());
            dataList.add(vo.getValue());
        });
        StuCountVO vo = new StuCountVO(clazzList, dataList);
        return vo;
    }

}
